﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Entity.Car_Rental;
using Data.Car_Rental;
using Entity.CommonEnums;
using Common.Background.Web.Controllers;
namespace Background.Controllers
{
    [ValidateInput(false)]
    public class HelperCenterController : BackgroundBaseController
    {
        IHelperCenterRepository iHelperCenterRepository = null;
        public HelperCenterController()
        {
            iHelperCenterRepository = new HelperCenterRepository();
        }
        //
        // GET: /HelperCenter/

        public ActionResult Index()
        {
            var model = iHelperCenterRepository.GetDetailModel();
            return View(model);
        }

        //
        // GET: /HelperCenter/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /HelperCenter/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /HelperCenter/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            HelperCenter entity = new HelperCenter();
            TryUpdateModel(entity);
            entity.CreateDate = DateTime.Now;
            entity.UpdateDate = DateTime.Now;
            entity.Status = (int)Status.Normal;
            if (entity.IsValid)
            {
                iHelperCenterRepository.Insert(entity);
                HelperCenterCategoryRepository.ReLoad();
                return AlertToUrl("Index");
            }
            else
            {
                entity.GetRuleViolations().ToList().ForEach(i =>
                {
                    ModelState.AddModelError(i.PropertyName, i.ErrorMessage);
                });
            }
            return View();
        }

        //
        // GET: /HelperCenter/Edit/5

        public ActionResult Edit(int? id)
        {
            if (!id.HasValue)
                return AlertToUrl("参数非法", "Index");
            var model = iHelperCenterRepository.Find(id);
            return View(model);
        }

        //
        // POST: /HelperCenter/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            HelperCenter entity = new HelperCenter();
            TryUpdateModel(entity);
            entity.UpdateDate = DateTime.Now;
            if (entity.IsValid)
            {
                iHelperCenterRepository.Update(entity);
                return AlertToUrl("Index");
            }
            else
            {
                entity.GetRuleViolations().ToList().ForEach(i =>
                {
                    ModelState.AddModelError(i.PropertyName, i.ErrorMessage);
                });
            }
            return View();
        }

        //
        // GET: /HelperCenter/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

    }
}
